'use strict'

function Clock(width,height) {
    var seconds;
	var minutes;
	var hours;
	var width,height;
	
	this.width= width;
	this.height = height;
	
	this.setSeconds = function(s){
		this.seconds = s;
	}
	
	this.setMinutes = function(m){
		this.minutes = m;
	}	
	
	this.setHours = function(h){
		this.hour = h;
	}
	
	this.drawSeconds = function(ctxt,seconds,minutes,hours,hourImage,minuteImage,secondImage){
		this.drawSecondsMinutesInCanvas(ctxt,seconds,minutes,hours,hourImage,minuteImage,secondImage);
	}	
	
	
	this.drawSecondsMinutesInCanvas = function(cxt,seconds,minutes,hours,hourImage,minuteImage,secondImage){
		
        //draw hourImage
        cxt.save();
		cxt.translate(200,320);
		console.log("5. hours is:"+hours);
		cxt.rotate(hours*30*Math.PI/180);	
		cxt.moveTo(0,0);
	    cxt.drawImage(hourImage, -40, 0, hourImage.width,-hourImage.height*0.6); 		    	
        cxt.restore();
		
        //draw MinuteImage  	
	    cxt.save();
		cxt.translate(200,320);
		console.log("4. minutes is:"+minutes);
		cxt.rotate(minutes*6*Math.PI/180);		    
		cxt.moveTo(0,0);
	    console.log("6. minutes width is:"+minuteImage.width+"，minutes height is:"+minuteImage.height+".");
	    cxt.drawImage(minuteImage, -40, 0, minuteImage.width,-minuteImage.height*0.8); 		    	
        cxt.restore(); 		    
	
		//draw Seconds		
		console.log("1. seconds is:"+seconds+", minutes is:"+minutes + ",hours is:"+hours); 
		// 将图像绘制到canvas上
		cxt.save();
		cxt.translate(200,320);		
	    cxt.rotate((this.seconds)*6*Math.PI/180);       	
		console.log("2. minutes is:"+minutes + ",hours is:"+hours); 
	    cxt.moveTo(0,0);
	    cxt.drawImage(secondImage, -40, 0, secondImage.width,-secondImage.height ); 		    	
        cxt.restore();  
	    console.log("3. minutes is:"+minutes + ",hours is:"+hours);
    }


    
	
	this.drawSkeleton = function(cxt){
        for(var i=0; i<12; i++) {
            cxt.save();
            cxt.lineWidth = 7;
            cxt.strokeStyle = "#000";
            cxt.translate(250,250);
            cxt.rotate(i*30*Math.PI/180);
            cxt.beginPath();
            cxt.moveTo(0,-170);
            cxt.lineTo(0,-190);
            cxt.stroke();
            cxt.closePath();
            cxt.restore();
        }
        // 时刻度结束

        // 分刻度开始
        for(var i=0; i<60; i++) {
            cxt.save();
            cxt.lineWidth = 5;
            cxt.strokeStyle = "#000";
            cxt.translate(250,250);
            cxt.rotate(i*6*Math.PI/180);
            cxt.beginPath();
            cxt.moveTo(0,-180);
            cxt.lineTo(0,-190);
            cxt.stroke();
            cxt.closePath();
            cxt.restore();
        } 
        // 分刻度结束
	}	
	
    this.hello = function () {
        alert('Hello, x:' + 200*Math.sin(2*Math.PI*10*6/360)+',y:'+(-200*Math.cos(2*Math.PI*10*6/360))+ '!');
    }
}